In [12]:
import pandas as pd
import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt
import plotly.express as px
In [2]:
dia = pd.read_csv(r'C:\Users\user\Downloads\diamonds.csv\diamonds.csv')
In [3]:
dia
Out[3]:
Unnamed: 0 carat cut color clarity depth table price x y z
0 1 0.23 Ideal E SI2 61.5 55.0 326 3.95 3.98 2.43
1 2 0.21 Premium E SI1 59.8 61.0 326 3.89 3.84 2.31
2 3 0.23 Good E VS1 56.9 65.0 327 4.05 4.07 2.31
3 4 0.29 Premium I VS2 62.4 58.0 334 4.20 4.23 2.63
4 5 0.31 Good J SI2 63.3 58.0 335 4.34 4.35 2.75
... ... ... ... ... ... ... ... ... ... ... ...
53935 53936 0.72 Ideal D SI1 60.8 57.0 2757 5.75 5.76 3.50
53936 53937 0.72 Good D SI1 63.1 55.0 2757 5.69 5.75 3.61
53937 53938 0.70 Very Good D SI1 62.8 60.0 2757 5.66 5.68 3.56
53938 53939 0.86 Premium H SI2 61.0 58.0 2757 6.15 6.12 3.74
53939 53940 0.75 Ideal D SI2 62.2 55.0 2757 5.83 5.87 3.64

53940 rows × 11 columns

In [4]:
dia.info()
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 53940 entries, 0 to 53939
Data columns (total 11 columns):
 #   Column      Non-Null Count  Dtype  
---  ------      --------------  -----  
 0   Unnamed: 0  53940 non-null  int64  
 1   carat       53940 non-null  float64
 2   cut         53940 non-null  object 
 3   color       53940 non-null  object 
 4   clarity     53940 non-null  object 
 5   depth       53940 non-null  float64
 6   table       53940 non-null  float64
 7   price       53940 non-null  int64  
 8   x           53940 non-null  float64
 9   y           53940 non-null  float64
 10  z           53940 non-null  float64
dtypes: float64(6), int64(2), object(3)
memory usage: 4.5+ MB
In [5]:
dia.duplicated().sum()
Out[5]:
0
In [6]:
a=dia.drop_duplicates()
a
Out[6]:
Unnamed: 0 carat cut color clarity depth table price x y z
0 1 0.23 Ideal E SI2 61.5 55.0 326 3.95 3.98 2.43
1 2 0.21 Premium E SI1 59.8 61.0 326 3.89 3.84 2.31
2 3 0.23 Good E VS1 56.9 65.0 327 4.05 4.07 2.31
3 4 0.29 Premium I VS2 62.4 58.0 334 4.20 4.23 2.63
4 5 0.31 Good J SI2 63.3 58.0 335 4.34 4.35 2.75
... ... ... ... ... ... ... ... ... ... ... ...
53935 53936 0.72 Ideal D SI1 60.8 57.0 2757 5.75 5.76 3.50
53936 53937 0.72 Good D SI1 63.1 55.0 2757 5.69 5.75 3.61
53937 53938 0.70 Very Good D SI1 62.8 60.0 2757 5.66 5.68 3.56
53938 53939 0.86 Premium H SI2 61.0 58.0 2757 6.15 6.12 3.74
53939 53940 0.75 Ideal D SI2 62.2 55.0 2757 5.83 5.87 3.64

53940 rows × 11 columns

In [7]:
a.duplicated().sum()
Out[7]:
0
In [8]:
a.isnull().sum()
Out[8]:
Unnamed: 0    0
carat         0
cut           0
color         0
clarity       0
depth         0
table         0
price         0
x             0
y             0
z             0
dtype: int64
In [9]:
dia.head(2)
Out[9]:
Unnamed: 0 carat cut color clarity depth table price x y z
0 1 0.23 Ideal E SI2 61.5 55.0 326 3.95 3.98 2.43
1 2 0.21 Premium E SI1 59.8 61.0 326 3.89 3.84 2.31

bar plot of color v/s price¶

In [10]:
a.columns
Out[10]:
Index(['Unnamed: 0', 'carat', 'cut', 'color', 'clarity', 'depth', 'table',
       'price', 'x', 'y', 'z'],
      dtype='object')
In [13]:
fig = px.bar(a, 
             x ='color', 
             y ='price',
             color ='color',
             animation_frame ='carat',
             hover_name ='depth')
fig.show()
In [14]:
a['cut'].unique()
Out[14]:
array(['Ideal', 'Premium', 'Good', 'Very Good', 'Fair'], dtype=object)
In [15]:
a['color'].unique()
Out[15]:
array(['E', 'I', 'J', 'H', 'F', 'G', 'D'], dtype=object)
In [16]:
a['clarity'].unique()
Out[16]:
array(['SI2', 'SI1', 'VS1', 'VS2', 'VVS2', 'VVS1', 'I1', 'IF'],
      dtype=object)
In [17]:
a.columns
Out[17]:
Index(['Unnamed: 0', 'carat', 'cut', 'color', 'clarity', 'depth', 'table',
       'price', 'x', 'y', 'z'],
      dtype='object')

- bar plot of cut v/s price¶

In [18]:
#  SCATTER PLOT
fig = px.bar(a, 
             x ='cut', 
             y ='price',
             color='color',
             animation_frame ='clarity',
             hover_name ='depth')
fig.show()
In [19]:
a.columns
Out[19]:
Index(['Unnamed: 0', 'carat', 'cut', 'color', 'clarity', 'depth', 'table',
       'price', 'x', 'y', 'z'],
      dtype='object')
In [20]:
a.head()
Out[20]:
Unnamed: 0 carat cut color clarity depth table price x y z
0 1 0.23 Ideal E SI2 61.5 55.0 326 3.95 3.98 2.43
1 2 0.21 Premium E SI1 59.8 61.0 326 3.89 3.84 2.31
2 3 0.23 Good E VS1 56.9 65.0 327 4.05 4.07 2.31
3 4 0.29 Premium I VS2 62.4 58.0 334 4.20 4.23 2.63
4 5 0.31 Good J SI2 63.3 58.0 335 4.34 4.35 2.75

SCATTER¶

In [21]:
fig = px.scatter(
    a, 
    x="carat", 
    y="price", 
    animation_frame="color", 
    animation_group="depth",
    size="table", 
    color="color", 
    hover_name="carat",
    title="Scatter plot for crat & price where animationFrame :-color & animationGroup :-depth"
)
fig.show()
In [22]:
fig = px.scatter(a, x="carat", y="price", animation_frame="color", color="color", hover_name="depth",
                title="Scatter plot for crat & price where animationFrame :-color")
fig.show()
In [23]:
fig=px.strip(a,x='cut',y='table',animation_frame="color", color="color", hover_name="depth",
            title="Strip plot for cut & table where animationFrame :-color")
fig.show()
In [24]:
fig=px.strip(a,x='cut',y='table',animation_frame="clarity", color="color", hover_name="depth",
             title="Strip plot for cut & table where animationFrame :-clarity")
fig.show()
In [25]:
a.columns
Out[25]:
Index(['Unnamed: 0', 'carat', 'cut', 'color', 'clarity', 'depth', 'table',
       'price', 'x', 'y', 'z'],
      dtype='object')
In [26]:
a.head(1)
Out[26]:
Unnamed: 0 carat cut color clarity depth table price x y z
0 1 0.23 Ideal E SI2 61.5 55.0 326 3.95 3.98 2.43
In [27]:
fig=px.scatter(a,x='cut',y="price",animation_frame="clarity", color="color", hover_name="depth")
fig.show()
In [28]:
a.head()
Out[28]:
Unnamed: 0 carat cut color clarity depth table price x y z
0 1 0.23 Ideal E SI2 61.5 55.0 326 3.95 3.98 2.43
1 2 0.21 Premium E SI1 59.8 61.0 326 3.89 3.84 2.31
2 3 0.23 Good E VS1 56.9 65.0 327 4.05 4.07 2.31
3 4 0.29 Premium I VS2 62.4 58.0 334 4.20 4.23 2.63
4 5 0.31 Good J SI2 63.3 58.0 335 4.34 4.35 2.75
In [29]:
fig=px.histogram(a,x='carat',y='depth',animation_frame="color", color="color", hover_name="price",
                 title="Histogram plot for carat &  where animationFrame :-color")
fig.show()
In [32]:
a.head(1)
Out[32]:
Unnamed: 0 carat cut color clarity depth table price x y z
0 1 0.23 Ideal E SI2 61.5 55.0 326 3.95 3.98 2.43
In [33]:
fig=px.line(a,x="table",y="price",animation_frame="cut", color="color", hover_name="price",markers=True,
            title="line chart for table & price where animationFrame :-cut")
fig.show()

BOX PLOT¶

In [34]:
a.head(1)
Out[34]:
Unnamed: 0 carat cut color clarity depth table price x y z
0 1 0.23 Ideal E SI2 61.5 55.0 326 3.95 3.98 2.43
In [35]:
fig=px.box(a,x="clarity",y='table',animation_frame="cut", color="color", hover_name="price",
            title="Box plot for clarity & table where animationFrame :-cut")
fig.show()
In [36]:
fig=px.box(a,x="color",y='table',animation_frame="cut", color="color", hover_name="price",points="all",
            title="Box plot for color & table where animationFrame :-cut")
fig.show()

VOILIN PLOT¶

In [37]:
a.head(2)
Out[37]:
Unnamed: 0 carat cut color clarity depth table price x y z
0 1 0.23 Ideal E SI2 61.5 55.0 326 3.95 3.98 2.43
1 2 0.21 Premium E SI1 59.8 61.0 326 3.89 3.84 2.31
In [38]:
fig=px.violin(a,y="price",animation_frame="cut", color="color", hover_name="price",points="all",
            title="Box plot for color & table where animationFrame :-cut")
fig.show()
In [39]:
fig=px.violin(a,y="price",animation_frame="cut", color="color", hover_name="price",
            title="Box plot for color & table where animationFrame :-cut with out points")
fig.show()

JOINT PLOT¶

In [40]:
fig = px.scatter(a,
                x="carat",
                y="price",
                marginal_x="histogram",
                marginal_y="histogram",
                animation_frame="cut",
                hover_name="price",
                color="color",
                title="Joint Plot")
fig.show()

BUBBLE PLOT¶

In [41]:
fig=px.scatter(a, x="table", y="price", size="depth",animation_frame="cut", color="color", hover_name="price",
            title="Bubble plot for table &price where animationFrame :-cut")

fig.show()

PAIR PLOT¶

In [42]:
a.head()
Out[42]:
Unnamed: 0 carat cut color clarity depth table price x y z
0 1 0.23 Ideal E SI2 61.5 55.0 326 3.95 3.98 2.43
1 2 0.21 Premium E SI1 59.8 61.0 326 3.89 3.84 2.31
2 3 0.23 Good E VS1 56.9 65.0 327 4.05 4.07 2.31
3 4 0.29 Premium I VS2 62.4 58.0 334 4.20 4.23 2.63
4 5 0.31 Good J SI2 63.3 58.0 335 4.34 4.35 2.75
In [43]:
fig= px.scatter_matrix(a,dimensions=["x","y","z"],color="color",title="Pair Plot")
fig.show()
C:\Users\user\anaconda3\lib\site-packages\plotly\express\_core.py:279: FutureWarning:

iteritems is deprecated and will be removed in a future version. Use .items instead.

In [ ]:
 
In [ ]:
 
In [ ]:
 
In [ ]:
 
In [ ]:
 
In [ ]:
 
In [ ]:
 
In [ ]:
 
In [ ]:
 
In [ ]:
 
In [ ]:
 
In [ ]:
 
In [ ]:
 
In [ ]:
 
In [ ]:
 
In [ ]:
 
In [ ]: